<?php


namespace app\admin\controller;


use app\admin\model\RealModel;
use app\admin\model\UserModel;
use app\api\model\Message;
use app\api\model\Mob;

class Real extends Common
{

    public function reallist(){
        $where = [];
        if(input('param.status','') !==''){
            $where = ['status'=>input('param.status')];
        }
        $list = RealModel::getList("id,user_telephone,true_name,IDCard,front,back,status,create_time",20,$where);
        return view('',['list'=>$list]);
    }
    public function getInfo(){
        $id= input('param.id',0);
        $info = RealModel::getInfoById($id);
        return view('',['info'=>$info]);
    }

    /**
     * @return \think\response\Json
     * @throws \think\exception\PDOException
     * 审核
     */
    public function check(){
        $id = input('post.id');
        $Info = RealModel::getInfo($id,'id,true_name,user_id');
        if(!$Info){
            return package(10001,'提交信息错误');
        }
        $status = input('post.status',0,'int');
        $admin_remarks = input('post.admin_remarks','','string');
        RealModel::startTrans();
        if(RealModel::setReal($id,$status,$admin_remarks)){
            if($status == 1){
                    UserModel::setUserReal($Info['user_id'],$Info['true_name']);
                    RealModel::commit();
                    $this->checkSuccess($id,$admin_remarks,$Info['user_id']);
                    return package(0,'操作成功');
            }else{
                RealModel::commit();
                $this->checkError($id,$admin_remarks,$Info['user_id']);
                return package(0,'操作成功');
            }
        }else{
            RealModel::rollback();
          return package(10001,'重复操作');
        }
    }
    private function checkSuccess($id,$admin_remarks,$user_id){
        return sendMsg($user_id,$admin_remarks,'实名成功通知',"实名");
    }
    private  function checkError($id,$admin_remarks,$user_id){
        return sendMsg($user_id,$admin_remarks,'实名失败通知',"实名");
    }

}